﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using SmallERP.MODEL.FoundationModel;
using SmallERP.MODEL.PrintManage;
using SmallERP.Bll.PrintManage;
using SmallERP.COM;
using System.Security.Cryptography;
using SmallERP.Bll.Com;
using Smallerp.Contracts;

namespace SmallERP.PrintManage
{
    public partial class FrmQuery : Form
    {
        private static FrmQuery instance = null;
        private Printer_info _printer;

        public delegate void SelectHander(int boardid);

        public SelectHander selectHander;

        public static FrmQuery GetInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmQuery();
                }

                return instance;
            }

        }


        public Printer_info Printer
        {
            set { _printer = value; }
        }
        private FrmQuery( )
        {
            InitializeComponent();
            
        }
        public  static IOperateDB _OperateDb;
        private void btnQuery_Click(object sender, EventArgs e)
        {
            BoardBLL boardBLL = new BoardBLL(_OperateDb);
            int boardid;
            int photoid;
            string customerName =string.Empty; 
            if (string.IsNullOrEmpty(txtBoardId.Text.Trim()))
            {
                boardid = 0;
            }
            else
            {
                boardid = Convert.ToInt32(txtBoardId.Text);
            }
            if (string.IsNullOrEmpty(txtPhotoId.Text.Trim()))
            {
                photoid = 0;
            }
            else
            {
                photoid = Convert.ToInt32(txtPhotoId.Text);
            }
            if (!string.IsNullOrEmpty(txtCustomerName.Text.Trim()))
            {
                customerName = txtCustomerName.Text.Trim();
            }
            gridControlBoard.DataSource = boardBLL.GetBoardInfoForQuery(boardid, photoid,customerName, (int)Status.MeasureUnit.Inch, _printer.PrinterID);
            gridViewBoard.RefreshData();
        }

        private void FrmQuery_Load(object sender, EventArgs e)
        {
            
        }

        private void FrmQuery_FormClosing(object sender, FormClosingEventArgs e)
        {
            instance = null;
        }

        private void gridViewBoard_DoubleClick(object sender, EventArgs e)
        {
            BoardModel boardInfo = (BoardModel)gridViewBoard.GetFocusedRow();
            if (boardInfo != null)
            {
                if (selectHander != null)
                {
                    Invoke(selectHander, new object[] { boardInfo.BoardId });
                    this.Hide();
                }
            }
        }
    }
}
